<%--
  Created by IntelliJ IDEA.
  User: ss
  Date: 2019/12/4
  Time: 14:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/easyui/themes/default/easyui.css">

    <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
<table id="dg"></table>

<script type="text/javascript">
    $(function () {
         $("#dg").datagrid({
             autoRowHeight:true,
             striped:true,
             nowrap:true,
             idField:'id',
             loadMsg:'正在加载',
             pagination:true,
             rownumbers:true,
             pageNumber:2,
             pageSize:20,
             pageList:[10,20,40,100],
             // singleSelect:true,  只许选择一行数据
             toolbar:[
                 {
                     id:'i_add',
                     text:'添加',
                     iconCls:'icon-add',
                     handler:add
                 },{
                     id:'i_del',
                     text:'删除',
                     iconCls:'icon-remove',
                     handler:del
                 }
                 ],
             url:'${pageContext.request.contextPath}/json/datagrid_data.json',
             columns:[
                 [
                     {field:'id',align:'center',resizable:true,checkbox:true},
                     {field:'name',title:'姓名',align:'center',resizable:true,width:200
                     },
                     {field:'sex',title:'性别',align:'center',width:300,
                     formatter:function (value,row,index) {
                              if (row.sex=="男"){
                                  return "1";
                              }else{
                                  return "0"
                              }
                     }}
                 ]
             ],
             onDblClickRow:function (rowIndex,rowData) {
                 alert(rowData.id);
             }
         })
    });


    function add() {
        $.messager.alert("添加","你点击了添加按钮","error")
    }

    function del() {

        var datagrid = $("#dg").datagrid('getSelections');

       if (datagrid.length<1){
           $.messager.alert("提示","你没有选中任何复选框");
       }else{
           var ss=new Array();
           for (var i=0;i<datagrid.length;i++){

              ss.push(datagrid[i].id);


           }


           $.messager.show({
               title:'所选id',
               msg:ss,
               timeout:5000
           })
       }
    }
</script>
</body>
</html>
